Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
binary-search
Advanced tools
This is a really tiny, stupid, simple binary search library for Node.JS. We wrote it because existing solutions were bloated and incorrect.
This version is a straight port of the Java version mentioned by Joshua Bloch in his article, Nearly All Binary Searches and Merge Sorts are Broken.
Thanks to Conrad Irwin and Michael Marino for, ironically, pointing out bugs.
var bs = require("binary-search");
bs([1, 2, 3, 4], 3, function(element, needle) { return element - needle; });
// => 2
bs([1, 2, 4, 5], 3, function(element, needle) { return element - needle; });
// => -3
Be advised that passing in a comparator function is required. Since you're probably using one for your sort function anyway, this isn't a big deal.
The comparator takes a 1st and 2nd argument of element and needle, respectively.
The comparator also takes a 3rd and 4th argument, the current index and array, respectively. You shouldn't normally need the index or array to compare values, but it's there if you do.
You may also, optionally, specify an input range as the final two parameters, in case you want to limit the search to a particular range of inputs. However, be advised that this is generally a bad idea (but sometimes bad ideas are necessary).
To the extent possible by law, The Dark Sky Company, LLC has waived all copyright and related or neighboring rights to this library.
FAQs
tiny binary search function with comparators
The npm package binary-search receives a total of 484,867 weekly downloads. As such, binary-search popularity was classified as popular.
We found that binary-search demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.